#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
#include<stdlib.h>
struct ListNode {
	int val;
	struct ListNode* next;
};
//struct ListNode* removeElements(struct ListNode* head, int val) {
//	struct ListNode* prev = NULL;
//	struct ListNode* cur = head;
//	while (cur)
//	{
//		if (cur->val != val)
//		{
//			prev = cur;
//			cur = cur->next;
//		}
//		else
//		{
//			if (prev == NULL)
//			{
//				head = cur->next;
//				free(cur);
//				cur = head;
//			}
//			else
//			{
//				prev->next = cur->next;
//				free(cur);
//				cur = prev->next;
//			}
//		}
//	}

////	return head;
////}
struct ListNode* removeElements(struct ListNode* head)
{
	struct ListNode* fast, * slow;
	fast = slow = head;
	while(fast&&fast->next)
	{
		slow = slow->next;
		fast = fast->next->next;
	}
	return slow;
}
int main()
{
	struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n2 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n3 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n4 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n5 = (struct ListNode*)malloc(sizeof(struct ListNode));
	/*struct ListNode* n6 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n7 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n8= (struct ListNode*)malloc(sizeof(struct ListNode));*/
	n1->val = 1;
	n2->val = 2;
	n3->val = 6;
	n4->val = 3;
	n5->val = 5;
	/*n6->val = 6;
	n7->val = 7;
	n8->val = 8;*/
	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next = n5;
	n5->next = NULL;
	/*n6->next = n7;
	n7->next = n8;
	n8->next = NULL;*/
	removeElements(6);
	return 0;
}

 